﻿using System;
using System.Collections.Generic;
using System.Text;
using XDesigner.ORM;

namespace XDesigner.ORM.Test
{
    [ORMType("Customers")]
    [System.ComponentModel.TypeConverter(typeof(MyTypeConverter))]
    public class CustomerClass
    {
        public CustomerClass()
        {
        }

        private string _ID = null;
        [ORMKeyField()]
        [ORMField("CustomerID")]
        [ORMNewValueGenerate(ORMNewValueGenerateStyle.GUID)]
        public virtual string ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        private string _CompanyName = null;

        [ORMDelay()]
        public virtual string CompanyName
        {
            get { return _CompanyName; }
            set { _CompanyName = value; }
        }

        private string _ContactName = null;

        public virtual  string ContactName
        {
            get { return _ContactName; }
            set { _ContactName = value; }
        }

        private string _ContactTitle = null;

        public virtual string ContactTitle
        {
            get { return _ContactTitle; }
            set { _ContactTitle = value; }
        }

        private string _Address = null;

        public virtual string Address
        {
            get { return _Address; }
            set { _Address = value; }
        }

        private string _City = null;

        public virtual string City
        {
            get { return _City; }
            set { _City = value; }
        }

        private string _Region = null;

        public virtual string Region
        {
            get { return _Region; }
            set { _Region = value; }
        }

        private string _PostalCode = null;

        public virtual string PostalCode
        {
            get { return _PostalCode; }
            set { _PostalCode = value; }
        }

        private string _Country = null;

        public virtual string Country
        {
            get { return _Country; }
            set { _Country = value; }
        }

        private string _Phone = null;

        public virtual string Phone
        {
            get { return _Phone; }
            set { _Phone = value; }
        }

        private string _Fax = null;

        public virtual string Fax
        {
            get { return _Fax; }
            set { _Fax = value; }
        }

        private string _Email = null;

        public virtual string Email
        {
            get { return _Email; }
            set { _Email = value; }
        }

        private string _WebSite = null;

        public virtual string WebSite
        {
            get { return _WebSite; }
            set { _WebSite = value; }
        }

        private List<OrderClass> _Orders = null;
        [ORMRelation(ORMRelationStyle.OneToMany, "CustomerID", UniteDeleteForDelete = true)]
        [ORMDelay()]
        public virtual List<OrderClass> Orders
        {
            get { return _Orders; }
            set { _Orders = value; }
        }

        public override string ToString()
        {
            return "Customer:" + this.CompanyName;
        }
    }

    public class MyTypeConverter : System.ComponentModel.TypeConverter
    {
        public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            return System.ComponentModel.TypeDescriptor.GetProperties(value, attributes);
        }
        public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context)
        {
            return true;
        }
    }
}